package com.ssm.service.Impl;

import com.ssm.entity.RoleResourceURL;
import com.ssm.entity.UserProfile;
import com.ssm.mapper.RoleResourceUrlMapper;
import com.ssm.mapper.UserProfileMapper;
import com.ssm.service.UserRoleService;
import com.ssm.service.UserRoleService_board;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 使用board表
 */
@Service
public class UserRoleServiceImpl_board implements UserRoleService_board {

    @Autowired
    private UserProfileMapper userRoleMapper;

    @Autowired
    private RoleResourceUrlMapper roleResourceUrlMapper;

    /**
     * 获取所有角色信息
     * @return
     */
    @Override
    public Set<UserProfile> getAllRoles() {
        Set<UserProfile> allRoles = userRoleMapper.getAllRoles();
        return allRoles;
    }

    /**
     * 获取某个角色的所有资源信息
     * @param role
     * @return
     */
    @Override
    public List<RoleResourceURL> getAllResourceURLByRole(String role) {
        List<RoleResourceURL> resources = roleResourceUrlMapper.getAllResourceURLByRole(role);
        return resources;
    }

    /**
     * 获取所有角色的所有资源  角色 1 - 资源 n
     * @return
     */
    @Override
    public List<List<RoleResourceURL>> getAllResourceURLAndAllRoles() {
        List<List<RoleResourceURL>> allRoleAndResources = new ArrayList<>();
        Set<UserProfile> allRoles =  getAllRoles();
        for (UserProfile Role : allRoles){
            List<RoleResourceURL> resourceURLs = getAllResourceURLByRole(Role.getType());
            allRoleAndResources.add(resourceURLs);
        }
        return allRoleAndResources;
    }

}
